<?php
require_once("database.php");

class xl_user extends database {
	
	
	function lay_ten($uid) 
	{		
		$sql = "SELECT name FROM user WHERE uid = '$uid'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function lay_hinh($uid) 
	{
		$sql = "SELECT pic FROM user WHERE uid = '$uid'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function kiem_tra($uid)
	{
		$sql = "Select * From user Where uid ='$uid'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function kiem_tra_dang_nhap($username, $password)
	{
		$password = md5($password);
		$sql = "Select * From user Where username ='$username' and password ='$password' limit 0,1";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	
	function cap_nhat_nguoi_dung($username, $password, $uid)
	{
		$password = md5($password);
		$sql = "UPDATE user SET username= '$username', password= '$password' WHERE uid = '$uid'";
		$this->setQuery($sql);
		return $this->query();
	}
	
	function danh_sach($vi_tri, $so_luong)
	{
		$vi_tri = intval($vi_tri);
		$so_luong = intval($so_luong);
		$sql = "select * from user limit $vi_tri, $so_luong";
		$this->setQuery($sql);
		return $this->loadAllRow();
	}
	function so_luong()
	{
		$sql = "select count(*) from user";
		$this->setQuery($sql);
		return $this->loadResult();
	}
	function xem($uid)
	{
		
		$sql = "select * from user where uid = '$uid'";
		$this->setQuery($sql);
		return $this->loadRow();
	}
	function xoa($uid)
	{
		
		$sql = "delete from user where uid = '$uid'";
		$this->setQuery($sql);
		$this->query();
	}
	function them($name, $pic, $link, $username, $bio, $quote, $sex, $timezone, $religion, $birthday, $hometown_location, $meeting_sex, $meeting_for, $relationship_status, $significant_other_id, $political, $current_location, $activities, $interests, $music, $tv, $movies, $books, $about_me, $notes_count, $wall_count, $status, $profile_url, $pic_with_logo, $allowed_restrictions, $website, $is_blocked, $contact_email, $email, $games, $work, $education, $sports, $favorite_athletes, $favorite_teams, $languages, $likes_count, $friend_count, $mutual_friend_count, $can_post, $locale, $verified, $profile_update_time)
	{
		$name = addslashes($name);
		$pic = addslashes($pic);
		$link = addslashes($link);
		$username = addslashes($username);
		$bio = addslashes($bio);
		$quote = addslashes($quote);
		$sex = addslashes($sex);
		$religion = addslashes($religion);
		$birthday = addslashes($birthday);
		$hometown_location = addslashes($hometown_location);
		$meeting_sex = addslashes($meeting_sex);
		$meeting_for = addslashes($meeting_for);
		$relationship_status = addslashes($relationship_status);
		$significant_other_id = intval($significant_other_id);
		$political = addslashes($political);
		$current_location = addslashes($current_location);
		$activities = addslashes($activities);
		$interests = addslashes($interests);
		$music = addslashes($music);
		$tv = addslashes($tv);
		$movies = addslashes($movies);
		$books = addslashes($books);
		$about_me = addslashes($about_me);
		$notes_count = intval($notes_count);
		$wall_count = intval($wall_count);
		$status = addslashes($status);
		$profile_url = addslashes($profile_url);
		$pic_with_logo = addslashes($pic_with_logo);
		$allowed_restrictions = addslashes($allowed_restrictions);
		$website = addslashes($website);
		$contact_email = addslashes($contact_email);
		$email = addslashes($email);
		$games = addslashes($games);
		$work = intval($work);
		$education = intval($education);
		$sports = addslashes($sports);
		$favorite_athletes = addslashes($favorite_athletes);
		$favorite_teams = addslashes($favorite_teams);
		$languages = addslashes($languages);
		$likes_count = intval($likes_count);
		$friend_count = intval($friend_count);
		$mutual_friend_count = intval($mutual_friend_count);
		$locale = addslashes($locale);
		$profile_update_time = intval($profile_update_time);

		$sql = "INSERT INTO user(name,pic,link,username,bio,quote,sex,timezone,religion,birthday,hometown_location,meeting_sex,meeting_for,relationship_status,significant_other_id,political,current_location,activities,interests,music,tv,movies,books,about_me,notes_count,wall_count,status,profile_url,pic_with_logo,allowed_restrictions,website,is_blocked,contact_email,email,games,work,education,sports,favorite_athletes,favorite_teams,languages,likes_count,friend_count,mutual_friend_count,can_post,locale,verified,profile_update_time) VALUES ('$name','$pic','$link','$username','$bio','$quote','$sex','$timezone','$religion','$birthday','$hometown_location','$meeting_sex','$meeting_for','$relationship_status','$significant_other_id','$political','$current_location','$activities','$interests','$music','$tv','$movies','$books','$about_me','$notes_count','$wall_count','$status','$profile_url','$pic_with_logo','$allowed_restrictions','$website','$is_blocked','$contact_email','$email','$games','$work','$education','$sports','$favorite_athletes','$favorite_teams','$languages','$likes_count','$friend_count','$mutual_friend_count','$can_post','$locale','$verified','$profile_update_time')";
		$this->setQuery($sql);
		return $this->query();
	}
	function cap_nhat($uid, $name, $link, $username, $bio, $quote, $sex, $timezone, $religion, $birthday, $hometown_location, $meeting_sex, $meeting_for, $relationship_status, $significant_other_id, $political, $current_location, $activities, $interests, $music, $tv, $movies, $books, $about_me, $notes_count, $wall_count, $status, $profile_url, $pic_with_logo, $allowed_restrictions, $website, $is_blocked, $contact_email, $email, $games, $work, $education, $sports, $favorite_athletes, $favorite_teams, $languages, $likes_count, $friend_count, $mutual_friend_count, $can_post, $locale, $verified, $profile_update_time)
	{
		$name = addslashes($name);
		//$pic = addslashes($pic);
		$link = addslashes($link);
		$username = addslashes($username);
		$bio = addslashes($bio);
		$quote = addslashes($quote);
		$sex = addslashes($sex);
		$religion = addslashes($religion);
		$birthday = addslashes($birthday);
		$hometown_location = addslashes($hometown_location);
		$meeting_sex = addslashes($meeting_sex);
		$meeting_for = addslashes($meeting_for);
		$relationship_status = addslashes($relationship_status);
		$significant_other_id = intval($significant_other_id);
		$political = addslashes($political);
		$current_location = addslashes($current_location);
		$activities = addslashes($activities);
		$interests = addslashes($interests);
		$music = addslashes($music);
		$tv = addslashes($tv);
		$movies = addslashes($movies);
		$books = addslashes($books);
		$about_me = addslashes($about_me);
		$notes_count = intval($notes_count);
		$wall_count = intval($wall_count);
		$status = addslashes($status);
		$profile_url = addslashes($profile_url);
		$pic_with_logo = addslashes($pic_with_logo);
		$allowed_restrictions = addslashes($allowed_restrictions);
		$website = addslashes($website);
		$contact_email = addslashes($contact_email);
		$email = addslashes($email);
		$games = addslashes($games);
		$work = intval($work);
		$education = intval($education);
		$sports = addslashes($sports);
		$favorite_athletes = addslashes($favorite_athletes);
		$favorite_teams = addslashes($favorite_teams);
		$languages = addslashes($languages);
		$likes_count = intval($likes_count);
		$friend_count = intval($friend_count);
		$mutual_friend_count = intval($mutual_friend_count);
		$locale = addslashes($locale);
		$profile_update_time = intval($profile_update_time);
		// ko update work va education
		$sql ="UPDATE user SET name= '$name', link= '$link', username= '$username', bio= '$bio', quote= '$quote', sex= '$sex', timezone= '$timezone', religion= '$religion', birthday= '$birthday', hometown_location= '$hometown_location', meeting_sex= '$meeting_sex', meeting_for= '$meeting_for', relationship_status= '$relationship_status', significant_other_id= '$significant_other_id', political= '$political', current_location= '$current_location', activities= '$activities', interests= '$interests', music= '$music', tv= '$tv', movies= '$movies', books= '$books', about_me= '$about_me', notes_count= '$notes_count', wall_count= '$wall_count', status= '$status', profile_url= '$profile_url', pic_with_logo= '$pic_with_logo', allowed_restrictions= '$allowed_restrictions', website= '$website', is_blocked= '$is_blocked', contact_email= '$contact_email', email= '$email', games= '$games', sports= '$sports', favorite_athletes= '$favorite_athletes', favorite_teams= '$favorite_teams', languages= '$languages', likes_count= '$likes_count', friend_count= '$friend_count', mutual_friend_count= '$mutual_friend_count', can_post= '$can_post', locale= '$locale', verified= '$verified', profile_update_time= '$profile_update_time' WHERE uid = '$uid'";
		
	/*	$sql ="UPDATE user SET name= '$name', link= '$link', username= '$username', bio= '$bio', quote= '$quote', sex= '$sex', timezone= '$timezone', religion= '$religion', birthday= '$birthday', hometown_location= '$hometown_location', meeting_sex= '$meeting_sex', meeting_for= '$meeting_for', relationship_status= '$relationship_status', significant_other_id= '$significant_other_id', political= '$political', current_location= '$current_location', activities= '$activities', interests= '$interests', music= '$music', tv= '$tv', movies= '$movies', books= '$books', about_me= '$about_me', notes_count= '$notes_count', wall_count= '$wall_count', status= '$status', profile_url= '$profile_url', pic_with_logo= '$pic_with_logo', allowed_restrictions= '$allowed_restrictions', website= '$website', is_blocked= '$is_blocked', contact_email= '$contact_email', email= '$email', games= '$games', work= '$work', education= '$education', sports= '$sports', favorite_athletes= '$favorite_athletes', favorite_teams= '$favorite_teams', languages= '$languages', likes_count= '$likes_count', friend_count= '$friend_count', mutual_friend_count= '$mutual_friend_count', can_post= '$can_post', locale= '$locale', verified= '$verified', profile_update_time= '$profile_update_time' WHERE uid = '$uid'";*/
		$this->setQuery($sql);
		return $this->query();
	}
	function tim_kiem ($tu_khoa)
	{
		$sql = "select * from user where	$name like %tu_khoa% or 	$pic like %tu_khoa% or 	$link like %tu_khoa% or 	$username like %tu_khoa% or 	$bio like %tu_khoa% or 	$quote like %tu_khoa% or 	$sex like %tu_khoa% or 	$religion like %tu_khoa% or 	$birthday like %tu_khoa% or 	$hometown_location like %tu_khoa% or 	$meeting_sex like %tu_khoa% or 	$meeting_for like %tu_khoa% or 	$relationship_status like %tu_khoa% or 	$political like %tu_khoa% or 	$current_location like %tu_khoa% or 	$activities like %tu_khoa% or 	$interests like %tu_khoa% or 	$music like %tu_khoa% or 	$tv like %tu_khoa% or 	$movies like %tu_khoa% or 	$books like %tu_khoa% or 	$about_me like %tu_khoa% or 	$status like %tu_khoa% or 	$profile_url like %tu_khoa% or 	$pic_with_logo like %tu_khoa% or 	$allowed_restrictions like %tu_khoa% or 	$website like %tu_khoa% or 	$contact_email like %tu_khoa% or 	$email like %tu_khoa% or 	$games like %tu_khoa% or 	$sports like %tu_khoa% or 	$favorite_athletes like %tu_khoa% or 	$favorite_teams like %tu_khoa% or 	$languages like %tu_khoa% or 	$locale like %tu_khoa%"; 
		$this->setQuery($sql);
		return $this->loadAllRow();	
	}
	
 }
?>